﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.view.*;
    import com.tudou.home.view.ad.*;
    import com.tudou.track.*;
    import com.tudou.utils.*;
    import flash.geom.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdLoadingCommand extends SimpleCommand
    {

        public function AdLoadingCommand()
        {
            return;
        }// end function

        private function sendTrack(param1:String, param2:Array = null) : void
        {
            var _loc_3:* = facade.retrieveProxy(AdProxy.NAME) as AdProxy;
            var _loc_4:* = facade.retrieveProxy(AdLoadingProxy.NAME) as AdLoadingProxy;
            if (_loc_3.adTracker && _loc_4.adItemInfo)
            {
                _loc_3.adTracker.adSend(_loc_4.adItemInfo, _loc_4.adThrowInfo, param1, param2);
            }
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_7:Rectangle = null;
            var _loc_2:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            var _loc_3:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            var _loc_4:* = facade.retrieveProxy(AdLoadingProxy.NAME) as AdLoadingProxy;
            var _loc_5:* = facade.retrieveMediator(AdLoadingMediator.NAME) as AdLoadingMediator;
            var _loc_6:* = facade.retrieveMediator(SkinMediator.NAME) as SkinMediator;
            switch(param1.getName())
            {
                case AdLoadingCommandSet.START:
                {
                    _loc_5.clearAd();
                    _loc_4.adItemInfo = _loc_2.getAdItemByType(AdType.LOADING);
                    _loc_4.adThrowInfo = _loc_2.throwInfo;
                    _loc_4.load();
                    break;
                }
                case AdLoadingCommandSet.CLEAR:
                {
                    _loc_5.clearAd();
                    break;
                }
                case AdLoadingCommandSet.LOADING_LOAD_COMPLETE:
                {
                    if (!_loc_3.playerStatus.hasReady)
                    {
                        _loc_5.adItemInfo = _loc_4.adItemInfo;
                        _loc_5.adThrowInfo = _loc_4.adThrowInfo;
                        _loc_5.setAdDisplay(_loc_4.primaryAd);
                        _loc_5.showAd();
                    }
                    break;
                }
                case AdLoadingCommandSet.LOADING_SHOW_START:
                {
                    sendTrack(NodeLog.AD_SHOW_START);
                    break;
                }
                case AdLoadingCommandSet.LOADING_SHOW_COMPLETE:
                {
                    break;
                }
                case AdLoadingCommandSet.LOADING_CLICK:
                {
                    openURL(_loc_4.adItemInfo.link);
                    sendTrack(NodeLog.AD_CLICK, [null]);
                    break;
                }
                case ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE:
                {
                    _loc_7 = PlayerConsts.FULLSCREEN_RECT;
                    _loc_5.goTransform(_loc_7.width, _loc_7.height, true);
                    break;
                }
                case ViewCommandSet.NORMALSCREEN_RESIZE:
                {
                    _loc_7 = PlayerConsts.NORMALSCREEN_RECT;
                    _loc_5.goTransform(_loc_7.width, _loc_7.height, false);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
